#ifndef CSETDIALOG_HPP
#define CSETDIALOG_HPP

#include <time.h>
#include <shlobj.h>
#include <shtypes.h>
#include <winbase.h>
#include <windows.h>
#include <strsafe.h>
#include <commctrl.h>

#define IDT_TOOLBAR_SAVE 11
#define IDT_TOOLBAR_CANCEL 12
#define IDB_BUTTON_REQFILE 13
#define IDB_BUTTON_RSPFILE 14
#define IDB_BUTTON_REQFOLDER 15
#define IDB_BUTTON_RSPFOLDER 16

class CSetDialog
{
public:
    CSetDialog() {}
    ~CSetDialog() {}
    CSetDialog(LPCTSTR lpszClassName, HINSTANCE hInstance)
    {
        m_hWnd = NULL;
        m_hParent = NULL;
        m_wcex = {0};
        m_hFont = NULL;
        m_rcMenuBar = {0};
        m_rcToolBar = {0};
        Register(lpszClassName, hInstance);
    }
    CSetDialog(const CSetDialog &) = delete;
    CSetDialog &operator=(const CSetDialog &) = delete;
    HWND GetHWND() const
    {
        return m_hWnd;
    }
    void SetToolBarRect(RECT rcToolBar)
    {
        m_rcToolBar = rcToolBar;
    }
    void SetMenuBarRect(RECT rcMenuBar)
    {
        m_rcMenuBar = rcMenuBar;
    }
    HFONT GetFont(TCHAR *lpFont, UINT uSize = 20)
    {
        if (m_hFont)
        {
            return m_hFont;
        }
        else
        {
            LOGFONT logfont;
            ZeroMemory(&logfont, sizeof(LOGFONT));
            logfont.lfHeight = uSize;
            if (lpFont)
            {
                StringCchCopy(logfont.lfFaceName, 255, lpFont);
            }
            else
            {
                StringCchCopy(logfont.lfFaceName, 255, TEXT("Microsoft YaHei"));
            }
            m_hFont = CreateFontIndirect(&logfont);
            return m_hFont;
        }
    }
    LRESULT Register(LPCTSTR lpszClassName, HINSTANCE hInstance)
    {
        m_wcex = {0};
        m_wcex.cbSize = sizeof(WNDCLASSEX);
        m_wcex.cbClsExtra = 0;                                                                       // 类的额外内存
        m_wcex.cbWndExtra = 0;                                                                       // 窗口额外内存
        m_wcex.hbrBackground = GetSysColorBrush(/*COLOR_3DFACE*/ COLOR_3DSHADOW /*COLOR_3DSHADOW*/); // 背景
        m_wcex.hCursor = LoadCursor(NULL, IDC_ARROW);                                                // 光标 第一个为NULL代表使用系统提供的光标
        m_wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);                                              // 图标 第一个为NULL代表使用系统提供的图标
        m_wcex.hInstance = hInstance;                                                                // 应用程序实例句柄
        m_wcex.lpfnWndProc = CSetDialog::WndProc;                                                    // 回调函数
        m_wcex.lpszClassName = lpszClassName;                                                        // 窗口类名称
        m_wcex.lpszMenuName = NULL;                                                                  // 菜单名称
        m_wcex.style = CS_HREDRAW | CS_VREDRAW;                                                      // 显示风格
        m_hInstance = hInstance;
        if (!RegisterClassEx(&m_wcex))
        {
            MessageBox(NULL, TEXT("Failed to register child window class"), TEXT("Error"), MB_OK | MB_ICONERROR);
            return -1;
        }
        return 0;
    }
    LRESULT Create(HWND hParent, LPRECT lpRect, LPCTSTR szWindowName)
    {
        // Create the child window
        RECT rect;
        if (!lpRect)
        {
            GetClientRect(hParent, &rect);
            lpRect = &rect;
        }
        m_nMenuBarHeight = m_rcMenuBar.bottom - m_rcMenuBar.top;
        m_nToolBarHeight = m_rcToolBar.bottom - m_rcToolBar.top;
        lpRect->top += m_nToolBarHeight;
        m_hWnd = CreateWindow(m_wcex.lpszClassName, szWindowName, WS_OVERLAPPEDWINDOW,
                              lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top,
                              hParent, NULL, m_hInstance, this);
        m_hParent = hParent;
        SetWindowLongPtr(m_hWnd, GWLP_USERDATA, (LONG_PTR)this);
        //模态对话框
        // EnableWindow(m_hParent, FALSE);
        CreateToolBar();
        CreateLeftCtrl();
        InitEditCtrlValue();
        ShowWindow(m_hWnd, SW_HIDE);
        return 0;
    }
    LRESULT CreateToolBar()
    {
        LPITEMIDLIST pidl;
        SHGetSpecialFolderLocation(m_hWnd, CSIDL_DESKTOP, &pidl);
        SHFILEINFO sfi = {0};
        //从系统里随机抽取icon图标
        HIMAGELIST hImageList = (HIMAGELIST)::SHGetFileInfo((LPCTSTR)pidl, 0, &sfi, sizeof(sfi), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
        // HIMAGELIST hImageList = ImageList_Create(32, 32, ILC_COLOR32 | ILC_MASK, 0, 0);

        //创建工具条控件
        HWND hToolBar = CreateWindow(TOOLBARCLASSNAME, NULL,
                                     WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, m_hWnd, NULL,
                                     NULL, NULL);

        //设置工具条的图片列表
        ::SendMessage(hToolBar, TB_SETIMAGELIST, 0, (LPARAM)hImageList);

        //添加一些按钮到工具条上去
        srand((unsigned int)time(NULL));
        UINT uButtonNums = 2;
        UINT uImgCount = ImageList_GetImageCount(hImageList);
        TBBUTTON tbButtons[uButtonNums] = {
            {MAKELONG(rand() % uImgCount, 0), IDT_TOOLBAR_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON | BTNS_AUTOSIZE, {0}, 0, (INT_PTR)TEXT("保存")},
            {MAKELONG(rand() % uImgCount, 0), IDT_TOOLBAR_CANCEL, TBSTATE_ENABLED, TBSTYLE_BUTTON | BTNS_AUTOSIZE, {0}, 0, (INT_PTR)TEXT("取消")}};

        ::SendMessage(hToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
        ::SendMessage(hToolBar, TB_ADDBUTTONS, (WPARAM)uButtonNums, (LPARAM)&tbButtons);

        //自动调整工具条的大小并显示
        ::SendMessage(hToolBar, TB_AUTOSIZE, 0, 0);
        ::SendMessage(hToolBar, TB_SETSTYLE, 0, TBSTYLE_FLAT | CCS_TOP);
        ::GetWindowRect(hToolBar, &m_rcToolBar);
        ::ShowWindow(hToolBar, true);
        return 0;
    }
    void CreateLeftCtrl()
    {
        RECT rcParent;
        //工具栏高度
        m_nMenuBarHeight = m_rcMenuBar.bottom - m_rcMenuBar.top;
        m_nToolBarHeight = m_rcToolBar.bottom - m_rcToolBar.top;
        //父窗口宽高
        GetClientRect(m_hParent, &rcParent);
        UINT uParentTop = rcParent.top + nWindowEdge + m_nToolBarHeight;

        m_hGroupBoxDb = CreateWindow(WC_BUTTON, TEXT("数据库"), WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 100, 100, 200, 200, m_hWnd, NULL, NULL, NULL);

        RECT rcDbStaticCtrl;
        rcDbStaticCtrl.left = rcParent.left + nWindowEdge + nTextCtrlLeft;
        rcDbStaticCtrl.top = uParentTop + nLineHeight;
        rcDbStaticCtrl.right = nTextCtrlWidth;
        rcDbStaticCtrl.bottom = nTextCtrlHeight;
        m_hHostText = CreateWindow(WC_STATIC, TEXT("主机："), WS_CHILD | WS_VISIBLE, rcDbStaticCtrl.left, rcDbStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcDbStaticCtrl.top = uParentTop + nLineHeight * 2;
        m_hPortText = CreateWindow(WC_STATIC, TEXT("端口："), WS_CHILD | WS_VISIBLE, rcDbStaticCtrl.left, rcDbStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcDbStaticCtrl.top = uParentTop + nLineHeight * 3;
        m_hUsernameText = CreateWindow(WC_STATIC, TEXT("用户名："), WS_CHILD | WS_VISIBLE, rcDbStaticCtrl.left, rcDbStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcDbStaticCtrl.top = uParentTop + nLineHeight * 4;
        m_hPasswordText = CreateWindow(WC_STATIC, TEXT("密码："), WS_CHILD | WS_VISIBLE, rcDbStaticCtrl.left, rcDbStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcDbStaticCtrl.top = uParentTop + nLineHeight * 5;
        m_hDatabaseText = CreateWindow(WC_STATIC, TEXT("数据库："), WS_CHILD | WS_VISIBLE, rcDbStaticCtrl.left, rcDbStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcDbStaticCtrl.top = uParentTop + nLineHeight * 6;
        m_hDbScanIntervalText = CreateWindow(WC_STATIC, TEXT("扫描间隔时间："), WS_CHILD | WS_VISIBLE, rcDbStaticCtrl.left, rcDbStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        SendMessage(m_hGroupBoxDb, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hHostText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hPortText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hUsernameText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hPasswordText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hDatabaseText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hDbScanIntervalText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);

        RECT rcDbEditCtrl;
        GetClientRect(m_hHostText, &rcDbEditCtrl);
        rcDbEditCtrl.left = nTextCtrlLeft + nTextCtrlWidth + nColWidth;
        rcDbEditCtrl.top = uParentTop + nLineHeight;
        rcDbEditCtrl.right = rcDbEditCtrl.left + nTextCtrlWidth;
        rcDbEditCtrl.bottom = rcDbEditCtrl.bottom;
        m_hHostEdit = CreateWindow(WC_EDIT, TEXT("主机："), WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL, rcDbEditCtrl.left, rcDbEditCtrl.top, rcDbEditCtrl.right, rcDbEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcDbEditCtrl.top = uParentTop + nLineHeight * 2;
        m_hPortEdit = CreateWindow(WC_EDIT, TEXT("端口："), WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL, rcDbEditCtrl.left, rcDbEditCtrl.top, rcDbEditCtrl.right, rcDbEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcDbEditCtrl.top = uParentTop + nLineHeight * 3;
        m_hUsernameEdit = CreateWindow(WC_EDIT, TEXT("用户名："), WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL, rcDbEditCtrl.left, rcDbEditCtrl.top, rcDbEditCtrl.right, rcDbEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcDbEditCtrl.top = uParentTop + nLineHeight * 4;
        m_hPasswordEdit = CreateWindow(WC_EDIT, TEXT("密码："), WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL, rcDbEditCtrl.left, rcDbEditCtrl.top, rcDbEditCtrl.right, rcDbEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcDbEditCtrl.top = uParentTop + nLineHeight * 5;
        m_hDatabaseEdit = CreateWindow(WC_EDIT, TEXT("数据库："), WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL, rcDbEditCtrl.left, rcDbEditCtrl.top, rcDbEditCtrl.right, rcDbEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcDbEditCtrl.top = uParentTop + nLineHeight * 6;
        m_hDbScanIntervalEdit = CreateWindow(WC_EDIT, TEXT("扫描间隔时间："), WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL, rcDbEditCtrl.left, rcDbEditCtrl.top, rcDbEditCtrl.right, rcDbEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        SendMessage(m_hHostEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hPortEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hUsernameEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hPasswordEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hDatabaseEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hDbScanIntervalEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);

        m_hGroupBoxFile = CreateWindow(WC_BUTTON, TEXT("交易文件"), WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 100, 100, 200, 200, m_hWnd, NULL, NULL, NULL);

        RECT rcFileStaticCtrl;
        rcFileStaticCtrl.left = nTextCtrlLeft + m_nSplitterWidth + nWindowEdge;
        rcFileStaticCtrl.top = uParentTop + nLineHeight;
        rcDbStaticCtrl.right = nTextCtrlWidth;
        rcDbStaticCtrl.bottom = nTextCtrlHeight;
        m_hReqFileText = CreateWindow(WC_STATIC, TEXT("请求控制文件："), WS_CHILD | WS_VISIBLE, rcFileStaticCtrl.left, rcFileStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcFileStaticCtrl.top = uParentTop + nLineHeight * 2;
        m_hRspFileText = CreateWindow(WC_STATIC, TEXT("应答控制文件："), WS_CHILD | WS_VISIBLE, rcFileStaticCtrl.left, rcFileStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcFileStaticCtrl.top = uParentTop + nLineHeight * 3;
        m_hReqFolderText = CreateWindow(WC_STATIC, TEXT("请求数据目录："), WS_CHILD | WS_VISIBLE, rcFileStaticCtrl.left, rcFileStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcFileStaticCtrl.top = uParentTop + nLineHeight * 4;
        m_hRspFolderText = CreateWindow(WC_STATIC, TEXT("应答数据目录："), WS_CHILD | WS_VISIBLE, rcFileStaticCtrl.left, rcFileStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcFileStaticCtrl.top = uParentTop + nLineHeight * 5;
        m_hFileScanIntervalText = CreateWindow(WC_STATIC, TEXT("扫描间隔时间："), WS_CHILD | WS_VISIBLE, rcFileStaticCtrl.left, rcFileStaticCtrl.top, rcDbStaticCtrl.right, rcDbStaticCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        SendMessage(m_hGroupBoxFile, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hReqFileText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hRspFileText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hReqFolderText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hRspFolderText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hFileScanIntervalText, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);

        RECT rcFileEditCtrl;
        GetClientRect(m_hHostText, &rcFileEditCtrl);
        rcFileEditCtrl.left = nTextCtrlLeft + nTextCtrlWidth + nColWidth + m_nSplitterWidth;
        rcFileEditCtrl.top = uParentTop + nLineHeight;
        rcFileEditCtrl.right = rcFileEditCtrl.left + nTextCtrlWidth - m_nSplitterWidth;
        rcFileEditCtrl.bottom = rcFileEditCtrl.bottom;
        m_hReqFileEdit = CreateWindow(WC_EDIT, TEXT("请求控制文件："), WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, rcFileEditCtrl.left, rcFileEditCtrl.top, rcFileEditCtrl.right, rcFileEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcFileEditCtrl.top = uParentTop + nLineHeight * 2;
        m_hRspFileEdit = CreateWindow(WC_EDIT, TEXT("应答控制文件："), WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, rcFileEditCtrl.left, rcFileEditCtrl.top, rcFileEditCtrl.right, rcFileEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcFileEditCtrl.top = uParentTop + nLineHeight * 3;
        m_hReqFolderEdit = CreateWindow(WC_EDIT, TEXT("请求数据目录："), WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, rcFileEditCtrl.left, rcFileEditCtrl.top, rcFileEditCtrl.right, rcFileEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcFileEditCtrl.top = uParentTop + nLineHeight * 4;
        m_hRspFolderEdit = CreateWindow(WC_EDIT, TEXT("应答数据目录："), WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, rcFileEditCtrl.left, rcFileEditCtrl.top, rcFileEditCtrl.right, rcFileEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        rcFileEditCtrl.top = uParentTop + nLineHeight * 5;
        m_hFileScanIntervalEdit = CreateWindow(WC_EDIT, TEXT("扫描间隔时间："), WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, rcFileEditCtrl.left, rcFileEditCtrl.top, rcFileEditCtrl.right, rcFileEditCtrl.bottom, m_hWnd, NULL, NULL, NULL);
        SendMessage(m_hReqFileEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hRspFileEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hReqFolderEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hRspFolderEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hFileScanIntervalEdit, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);

        RECT rcFileBtnCtrl;
        GetClientRect(m_hReqFileEdit, &rcFileBtnCtrl);
        rcFileBtnCtrl.left = nTextCtrlLeft + nTextCtrlWidth + nColWidth + m_nSplitterWidth + rcFileBtnCtrl.right + nColWidth;
        rcFileBtnCtrl.top = uParentTop + nLineHeight;
        rcFileBtnCtrl.right = 80;
        rcFileBtnCtrl.bottom = 30;
        m_hReqFileBtn = CreateWindow(WC_BUTTON, TEXT("浏览"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, rcFileBtnCtrl.left, rcFileBtnCtrl.top, rcFileBtnCtrl.right, rcFileBtnCtrl.bottom, m_hWnd, (HMENU)IDB_BUTTON_REQFILE, NULL, NULL);
        rcFileBtnCtrl.top = uParentTop + nLineHeight * 2;
        m_hRspFileBtn = CreateWindow(WC_BUTTON, TEXT("浏览"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, rcFileBtnCtrl.left, rcFileBtnCtrl.top, rcFileBtnCtrl.right, rcFileBtnCtrl.bottom, m_hWnd, (HMENU)IDB_BUTTON_RSPFILE, NULL, NULL);
        rcFileBtnCtrl.top = uParentTop + nLineHeight * 3;
        m_hReqFolderBtn = CreateWindow(WC_BUTTON, TEXT("浏览"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, rcFileBtnCtrl.left, rcFileBtnCtrl.top, rcFileBtnCtrl.right, rcFileBtnCtrl.bottom, m_hWnd, (HMENU)IDB_BUTTON_REQFOLDER, NULL, NULL);
        rcFileBtnCtrl.top = uParentTop + nLineHeight * 4;
        m_hRspFolderBtn = CreateWindow(WC_BUTTON, TEXT("浏览"), WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, rcFileBtnCtrl.left, rcFileBtnCtrl.top, rcFileBtnCtrl.right, rcFileBtnCtrl.bottom, m_hWnd, (HMENU)IDB_BUTTON_RSPFOLDER, NULL, NULL);
        SendMessage(m_hReqFileBtn, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hRspFileBtn, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hReqFolderBtn, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);
        SendMessage(m_hRspFolderBtn, WM_SETFONT, (WPARAM)GetFont(NULL), TRUE);

        // HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, TEXT("./bitmap/test19_cartesian_canvas02.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
        // HWND hsti = CreateWindow(WC_STATIC, TEXT(""), WS_CHILD | WS_VISIBLE | SS_BITMAP, 220, 20, 0, 0, m_hWnd, (HMENU)1, NULL, NULL);
        // SendMessage(hsti, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap);
    }
    LRESULT InitEditCtrlValue()
    {
        SetWindowText(m_hHostEdit, TEXT(""));
        SetWindowText(m_hPortEdit, TEXT(""));
        SetWindowText(m_hUsernameEdit, TEXT(""));
        SetWindowText(m_hPasswordEdit, TEXT(""));
        SetWindowText(m_hDatabaseEdit, TEXT(""));
        SetWindowText(m_hDbScanIntervalEdit, TEXT(""));
        SetWindowText(m_hReqFileEdit, TEXT(""));
        SetWindowText(m_hRspFileEdit, TEXT(""));
        SetWindowText(m_hReqFolderEdit, TEXT(""));
        SetWindowText(m_hRspFolderEdit, TEXT(""));
        SetWindowText(m_hFileScanIntervalEdit, TEXT(""));
        return 0;
    }
    WINBOOL ChooseFolder(LPTSTR strFoldernameBuffer)
    {
        BROWSEINFO bi = {0};
        bi.hwndOwner = NULL;                     //拥有着窗口句柄，为NULL表示对话框是非模态的，实际应用中一般都要有这个句柄
        bi.pszDisplayName = strFoldernameBuffer; //接收文件夹的缓冲区
        bi.lpszTitle = TEXT("选择一个文件夹");   //标题
        bi.ulFlags = BIF_NEWDIALOGSTYLE;
        LPITEMIDLIST idl = SHBrowseForFolder(&bi);
        return SHGetPathFromIDList(idl, strFoldernameBuffer);
    }
    WINBOOL ChooseFile(LPTSTR strFilenameBuffer)
    {
        OPENFILENAME ofn = {0};
        TCHAR strFilename[MAX_PATH] = {0};
        ofn.lStructSize = sizeof(OPENFILENAME);                                 //结构体大小
        ofn.hwndOwner = NULL;                                                   //拥有着窗口句柄，为NULL表示对话框是非模态的，实际应用中一般都要有这个句柄
        ofn.lpstrFilter = TEXT("所有文件\0*.*\0C/C++ Flie\0*.cpp;*.c;*.h\0\0"); //设置过滤
        ofn.nFilterIndex = 1;                                                   //过滤器索引
        ofn.lpstrFile = strFilename;                                            //接收返回的文件名，注意第一个字符需要为NULL
        ofn.nMaxFile = sizeof(strFilename);                                     //缓冲区长度
        ofn.lpstrInitialDir = NULL;                                             //初始目录为默认
        ofn.lpstrTitle = TEXT("请选择一个文件");                                //使用系统默认标题留空即可
        ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;   //文件、目录必须存在，隐藏只读选项
        WINBOOL bRet = GetOpenFileName(&ofn);
        StringCchPrintf(strFilenameBuffer, MAX_PATH, TEXT("%s"), strFilename);
        return bRet;
    }
    void TcharToChar(const TCHAR *tchar, char *_char)
    {
        int iLength;
        //获取字节长度
        iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);
        //将tchar值赋给_char
        WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);
    }
    void CharToTchar(const char *_char, TCHAR *tchar)
    {
        int iLength;
        iLength = MultiByteToWideChar(CP_ACP, 0, _char, strlen(_char) + 1, NULL, 0);
        MultiByteToWideChar(CP_ACP, 0, _char, strlen(_char) + 1, tchar, iLength);
    }
    static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        CSetDialog *pThis = (CSetDialog *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
        if (pThis)
        {
            return pThis->WindowProc(hWnd, uMsg, wParam, lParam);
        }
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch (uMsg)
        {
        case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            HPEN hPen = CreatePen(PS_NULL, 1, RGB(0, 0, 0));
            HPEN holdPen = (HPEN)SelectObject(hdc, hPen);
            HBRUSH hBrush = CreateSolidBrush(RGB(200, 255, 200));
            HBRUSH holdBrush = (HBRUSH)SelectObject(hdc, hBrush);

            RECT rect;
            GetClientRect(hWnd, &rect);
            // Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);

            SelectObject(hdc, holdPen);
            SelectObject(hdc, holdBrush);
            DeleteObject(hPen);
            DeleteObject(hBrush);
            ReleaseDC(hWnd, hdc);
            EndPaint(hWnd, &ps);
            break;
        }
        case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDT_TOOLBAR_SAVE:
            {
                MessageBox(NULL, TEXT("IDT_TOOLBAR_SAVE"), TEXT("IDT_TOOLBAR_SAVE"), 0);
                break;
            }
            case IDT_TOOLBAR_CANCEL:
            {
                MessageBox(NULL, TEXT("IDT_TOOLBAR_CANCEL"), TEXT("IDT_TOOLBAR_CANCEL"), 0);
                break;
            }
            case IDB_BUTTON_REQFILE:
            {
                char cFilename[MAX_PATH] = {0};
                TCHAR szFilename[MAX_PATH] = {0};
                if (ChooseFile(szFilename))
                {
                    TcharToChar(szFilename, cFilename);
                    SetWindowText(m_hReqFileEdit, szFilename);
                }
                break;
            }
            case IDB_BUTTON_RSPFILE:
            {
                char cFilename[MAX_PATH] = {0};
                TCHAR szFilename[MAX_PATH] = {0};
                if (ChooseFile(szFilename))
                {
                    TcharToChar(szFilename, cFilename);
                    SetWindowText(m_hRspFileEdit, szFilename);
                }
                break;
            }
            case IDB_BUTTON_REQFOLDER:
            {
                char cFilename[MAX_PATH] = {0};
                TCHAR szFoldername[MAX_PATH] = {0};
                if (ChooseFolder(szFoldername))
                {
                    TcharToChar(szFoldername, cFilename);
                    SetWindowText(m_hReqFolderEdit, szFoldername);
                }
                break;
            }
            case IDB_BUTTON_RSPFOLDER:
            {
                char cFilename[MAX_PATH] = {0};
                TCHAR szFoldername[MAX_PATH] = {0};
                if (ChooseFolder(szFoldername))
                {
                    TcharToChar(szFoldername, cFilename);
                    SetWindowText(m_hRspFolderEdit, szFoldername);
                }
                break;
            }
            default:
                break;
            }
            break;
        }
        case WM_KEYDOWN:
        {
            if (wParam == VK_TAB)
            {
                // SetFocus(GetNextDlgTabItem(GetParent(hWnd), hWnd, FALSE));
            }
            break;
        }
        case WM_SIZE:
        {
            // RECT rcParent;
            // GetClientRect(hWnd, &rcParent);
            // rcParent.top += m_rcToolBar.bottom - m_rcToolBar.top;
            // MoveWindow(m_hWnd, rcParent.left, rcParent.top, rcParent.right, rcParent.bottom, TRUE);

            RECT rcWnd;
            GetClientRect(hWnd, &rcWnd);
            rcWnd.left = rcWnd.left + nWindowEdge;
            rcWnd.top = rcWnd.top + nWindowEdge + m_nToolBarHeight;
            rcWnd.right = m_nSplitterWidth;
            rcWnd.bottom = rcWnd.bottom - rcWnd.top - nWindowEdge;
            MoveWindow(m_hGroupBoxDb, rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, TRUE);
            GetClientRect(hWnd, &rcWnd);
            rcWnd.left = rcWnd.left + nWindowEdge + m_nSplitterWidth;
            rcWnd.top = rcWnd.top + nWindowEdge + m_nToolBarHeight;
            rcWnd.right = rcWnd.right - m_nSplitterWidth - nWindowEdge * 2;
            rcWnd.bottom = rcWnd.bottom - rcWnd.top - nWindowEdge;
            MoveWindow(m_hGroupBoxFile, rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, TRUE);
            InvalidateRect(hWnd, NULL, FALSE);

            EnumChildWindows(hWnd, EnumChildProc, lParam);
            break;
        }
        case WM_MOUSEMOVE:
        {
            int xPos = LOWORD(lParam);
            int yPos = HIWORD(lParam);
            TCHAR buffer[256];
            StringCchPrintf(buffer, 256, TEXT("xPos: %d, yPos: %d"), xPos, yPos);
            // SetWindowText(m_hParent, buffer);
            break;
        }
        case WM_CLOSE:
        {
            // DestroyWindow(hWnd);
            ShowWindow(m_hWnd, SW_HIDE);
            SetForegroundWindow(m_hParent);
            return 0;
        }
        case WM_DESTROY:
        {
            // PostQuitMessage(0);
            break;
        }
        default:
            break;
        }
        return DefWindowProc(m_hWnd, uMsg, wParam, lParam);
    }
    static BOOL CALLBACK EnumChildProc(HWND hWnd, LPARAM lParam)
    {
        SendMessage(hWnd, WM_SIZE, 0, lParam);
        return TRUE;
    }

public:
    UINT nLineHeight = 50;
    UINT nColWidth = 10;
    UINT nTextCtrlLeft = 10;
    UINT nTextCtrlWidth = 100;
    UINT nTextCtrlHeight = 30;
    UINT nWindowEdge = 5;
    UINT m_nSplitterWidth = 360;

    HWND m_hGroupBoxDb;
    HWND m_hHostText;
    HWND m_hPortText;
    HWND m_hUsernameText;
    HWND m_hPasswordText;
    HWND m_hDatabaseText;
    HWND m_hDbScanIntervalText;

    HWND m_hHostEdit;
    HWND m_hPortEdit;
    HWND m_hUsernameEdit;
    HWND m_hPasswordEdit;
    HWND m_hDatabaseEdit;
    HWND m_hDbScanIntervalEdit;

    HWND m_hGroupBoxFile;
    HWND m_hReqFileText;
    HWND m_hRspFileText;
    HWND m_hReqFolderText;
    HWND m_hRspFolderText;
    HWND m_hFileScanIntervalText;

    HWND m_hReqFileEdit;
    HWND m_hRspFileEdit;
    HWND m_hReqFolderEdit;
    HWND m_hRspFolderEdit;
    HWND m_hFileScanIntervalEdit;

    HWND m_hReqFileBtn;
    HWND m_hRspFileBtn;
    HWND m_hReqFolderBtn;
    HWND m_hRspFolderBtn;

    UINT m_nMenuBarHeight;
    UINT m_nToolBarHeight;
    HWND m_hWnd;
    HWND m_hParent;
    HFONT m_hFont;
    WNDCLASSEX m_wcex;
    RECT m_rcMenuBar;
    RECT m_rcToolBar;
    HINSTANCE m_hInstance;
};

#endif